/**
*	@file QueryTree.h
*
*	@brief this header defines class for query tree
*
*	@author li yuchen
*
*	@date 1/28/2011
*/
#ifndef QUERYTREE_H
#define QUERYTREE_H

#include "QueryTNode.h"
#include "QueryVarTable.h"
#include <vector>
#include <string>
#include <sstream>
using namespace std;

class QueryTree{
public:

	/** @return the query tree */
	static vector<QueryTNode*>*	get_vp_query_tnodes(){ return &vp_query_tnodes_; };

	/**	@return the clustered query clause */
	static vector<vector<QueryTNode*> >* get_p_query_matrix() { return &query_matrix_ ;}; 

	/** @return final result tuple */
	static vector<QueryVarIdx>* get_pv_result_tuple() { return &result_tuple_; };

	/** @return the number of query clause in total */
	static int get_size(){ return size_; };

	/** @brief set the number of query clauses before optimize */
	static void set_size(int num_of_clauses) { size_ = num_of_clauses; };

	/**	
	*	@brief Add a query node with given its type and argument a and b
	*		and returns newly added QueryTNode reference
	*/
	static QueryTNode* AddQueryTNode(QueryType q_type, QueryArgumentValue argument_a, QueryArgumentValue argument_b);

	/** 
	*	@brief set the constraint for the pattern query
	*		left could be NULL
	*/
	static void SetPattern(QueryTNode* query, TNode* pattern, bool isRelaxed);

	static string	ToString();
	static string	MatrixToString();

	/** @brief clean up */
	static void		ClearQueryTree();

	static vector<bool>* get_pv_query_var_type() { return &query_var_type_; };

private:

	static vector<QueryTNode*>	vp_query_tnodes_;
	static vector<vector<QueryTNode*> > query_matrix_;
	static vector<QueryVarIdx> result_tuple_;
	/* true is string, false is constant */
	static vector<bool>        query_var_type_;
	static int size_;
};

#endif